This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(sf)
## Warning: package 'sf' was built under R version 4.3.3
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library(rvest)
## Warning: package 'rvest' was built under R version 4.3.3
library(leaflet)
library(here)
## Warning: package 'here' was built under R version 4.3.3
## here() starts at C:/GitHub/opengisci/wt25_josephholler
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'ggplot2' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ readr::guess_encoding() masks rvest::guess_encoding()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Load counties of Vermont using Tigris package
vermont_counties |>
ggplot() +
geom_sf(aes(geometry = geometry, fill = AWATER))
Query all states
Map all states
all_states |>
ggplot() +
geom_sf(aes(geometry = geometry, fill = AWATER/ALAND))
Shift the geometry of the coordinates and filter out territories
all_states |>
shift_geometry() |>
filter(as.numeric(GEOID) < 60) |>
ggplot() +
geom_sf(aes(geometry = geometry, fill = AWATER/ALAND))
Scrape alcohol data
url <- "https://wisevoter.com/state-rankings/alcohol-consumption-by-state/"
alcohol <- url |>
read_html() |>
html_element("table") |>
html_table()
Join alcohol to states
all_states_booze <- all_states |>
filter(GEOID < 60) |>
left_join(alcohol, by = join_by("NAME" == "State"))
all_states_booze <- all_states_booze |>
mutate(alcohol_per_cap = as.numeric(str_remove(`Alcohol Consumption Per Capita`, " gal")))
Make a map!
all_states_booze |>
shift_geometry() |>
filter(as.numeric(GEOID) < 60) |>
ggplot() +
geom_sf(aes(geometry = geometry, fill = alcohol_per_cap)) +
scale_fill_binned()
Make an interactive map with Leaflet
leaflet() |>
addTiles() |>
addMarkers(lat= 44.0139,
lng = -73.1814,
label = "BiHall",
popup = "Here we are")
Load the dataset
volcanoes <- read_tsv(here("data_public", "volcano_data.tsv"))
## Rows: 1608 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (7): Search Parameters, Volcano Name, Country, Location, Type, Status, L...
## dbl (4): Volcano Number, Latitude, Longitude, Elevation (m)
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(volcanoes, 5)
## # A tibble: 5 × 11
## `Search Parameters` `Volcano Number` `Volcano Name` Country Location Latitude
## <chr> <dbl> <chr> <chr> <chr> <dbl>
## 1 [] NA <NA> <NA> <NA> NA
## 2 <NA> 250010 St. Andrew Str… Papua … Admiral… -2.38
## 3 <NA> 250020 Baluan United… Admiral… -2.57
## 4 <NA> 250030 Central Bismar… United… Admiral… -3.03
## 5 <NA> NA Dacht-I-Navar … Afghan… Afghani… 34.0
## # ℹ 5 more variables: Longitude <dbl>, `Elevation (m)` <dbl>, Type <chr>,
## # Status <chr>, `Last Known Eruption` <chr>
Map the volcanoes
volcanoes |>
leaflet() |>
addTiles() |>
addMarkers(lat = ~Latitude,
lng = ~Longitude,
label = ~`Volcano Name`)
Cluster markers
volcanoes |>
leaflet() |>
addTiles() |>
addMarkers(lat = ~Latitude,
lng = ~Longitude,
label = ~`Volcano Name`,
clusterOptions = markerClusterOptions())
volcanoes |>
leaflet() |>
addTiles() |>
addCircleMarkers(lat = ~Latitude,
lng = ~Longitude,
label = ~`Volcano Name`,
radius = 5,
color = "red")
Map alcohol consumption with leaflet
all_states_booze |>
filter(GEOID < 60) |>
leaflet() |>
addPolygons(label = ~NAME)
middcourses reviews courses/professors and builds schedules